package jmine.tec.hydra.services.excluir;

import jmine.tec.di.annotation.Injected;
import jmine.tec.hydra.HydraController;
import jmine.tec.hydra.domain.HydraActivation;
import jmine.tec.persist.PersistMessages;
import jmine.tec.services.annotations.Execution;
import jmine.tec.services.annotations.Input;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.api.ActionsEnum;
import jmine.tec.services.api.ServiceExecutionException;
import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.persist.dao.BeanNotFoundException;

/**
 * Serviço de exclusão de uma ativação de integração.
 * 
 * @author piercio
 */
@ServiceImplementor(action = ActionsEnum.EXCLUIR)
public class HydraActivationService {

    public static final String MNEMONICO = "Mnemonico";

    private String mnemonico;

    protected HydraController hydraController;

    /**
     * Executa o serviço e remove um {@link HydraActivation}
     * 
     * @throws ServiceExecutionException caso não encontre a especificação.
     */
    @Execution
    public void executeService() throws ServiceExecutionException {
        try {
            BaseDAO<HydraActivation> dao = this.hydraController.getDAOFactory().getGenericDAO(HydraActivation.class);
            HydraActivation actv = dao.findByNaturalKey(this.mnemonico);
            actv.getPersister().remove();
        } catch (BeanNotFoundException e) {
            throw new ServiceExecutionException(PersistMessages.BEAN_NOT_FOUND_BY_NATURAL_KEY.create(HydraActivation.class, this.mnemonico));
        }
    }

    /**
     * @param hydraController o hydraController
     */
    @Injected
    public void setHydraController(HydraController hydraController) {
        this.hydraController = hydraController;
    }

    /**
     * @param mnemonico o valor para o campo mnemonico
     */
    @Input(fieldName = MNEMONICO)
    public void setMnemonico(String mnemonico) {
        this.mnemonico = mnemonico;
    }

}
